package ru.alt22.visor.php.unittests.core;

import java.util.Enumeration;
import java.util.Vector;

public class PHPTestResult {
	private boolean shouldStop = false;

	private Vector<PHPTestListenter> listeners = new Vector<PHPTestListenter>(); 

	public void run(final PHPTest test, PHPProxy proxy) {
		test.run(this, proxy);
	}

	public boolean shouldStop() {
		return shouldStop;
	}

	public void stop() {
		shouldStop = true;
	}

	public void addListener(PHPTestListenter listener) {
		if (listeners.contains(listener)) {
			return;
		}
		listeners.add(listener);
	}

	public void removeListener(PHPTestListenter listener) {
		listeners.remove(listener);
	}

	public void testSuiteStarted(PHPTestSuite suite) {
		for (Enumeration<PHPTestListenter> e = listeners(); e.hasMoreElements(); ) {
			e.nextElement().testSuiteStarted(suite);
		}
	}

	public void testSuiteFinished(PHPTestSuite suite) {
		for (Enumeration<PHPTestListenter> e = listeners(); e.hasMoreElements(); ) {
			e.nextElement().testSuiteFinished(suite);
		}
	}

	public void testCaseStarted(PHPTestCase test) {
		for (Enumeration<PHPTestListenter> e = listeners(); e.hasMoreElements(); ) {
			e.nextElement().testCaseStarted(test);
		}
	}

	public void testCaseFinished(PHPTestCase test) {
		for (Enumeration<PHPTestListenter> e = listeners(); e.hasMoreElements(); ) {
			e.nextElement().testCaseFinished(test);
		}
	}

	private Enumeration<PHPTestListenter> listeners() {
		return listeners.elements();
	}

}